﻿using System;
using System.Collections.Generic;
using System.IO;
using ProjScan.Modules;
using ProjScan.RecordManager.AssetData;
using ProjScan.Tools;
using UnityEditor;
using UnityEngine;

namespace ProjScan.RecordManager
{
	// Token: 0x0200028A RID: 650
	internal class ShaderRecordManager : RecordManagerBase<ShaderAssetData>
	{
		// Token: 0x0600112C RID: 4396 RVA: 0x00050B0C File Offset: 0x0004ED0C
		public override void PrepareAssets()
		{
			Singleton<PerformanceMeasurer>.Instance.StartStateExecutionMeasure("ProjShader");
			ScanLog.Instance.LogInfo(Module.Effects_Play_Check, ScanLog.Stage.s3, this.TableTag, "Scan");
			this.datas = new List<ShaderAssetData>();
			ToolsHelper.ShowProgressBar(this.TableTag, "Preparing shader data...", 0f, false);
			List<string> list = new List<string>
			{
				"shader"
			};
			int num = AssetPathManager.Instance.artPathList.Length;
			for (int i = 0; i < num; i++)
			{
				ToolsHelper.ShowProgressBar(this.TableTag, string.Format("Preparing {0} ({1})...", this.TableTag, this.datas.Count), (float)i / (float)num, false);
				string text = AssetPathManager.Instance.artPathList[i];
				string item = Path.GetExtension(text).ToLower().Replace(".", "");
				bool flag = list.Contains(item);
				if (flag)
				{
					this.ActiveAllRecord();
					bool flag2 = this.CheckAssetPathRules(text);
					if (flag2)
					{
						ShaderImporter shaderImporter = AssetImporter.GetAtPath(text) as ShaderImporter;
						bool flag3 = shaderImporter != null;
						if (flag3)
						{
							Shader shader = AssetDatabase.LoadAssetAtPath<Shader>(text);
							bool flag4 = shader != null;
							if (flag4)
							{
								int id = 0;
								try
								{
									id = AssetPathManager.Instance.GetID(Path.GetDirectoryName(text));
								}
								catch (Exception ex)
								{
									ScanLog instance = ScanLog.Instance;
									ScanLog.LogLevel logLevel = ScanLog.LogLevel.EXCEPTION;
									Module module = Module.Shader_Analysis;
									string tableTag = this.TableTag;
									string[] array = new string[5];
									int num2 = 0;
									Type type = ex.GetType();
									array[num2] = ((type != null) ? type.ToString() : null);
									array[1] = "\n";
									array[2] = ex.Message;
									array[3] = "\n";
									array[4] = ex.StackTrace;
									instance.LogInfo(logLevel, module, tableTag, string.Concat(array));
									Debug.LogError("Proj Scan: Shader Analyzer 扫描失败, Shader  @ " + text);
								}
								ShaderAssetData shaderAssetData = new ShaderAssetData(id, text, shader, shaderImporter)
								{
									id = this.datas.Count
								};
								this.ValidateAsset(shaderAssetData);
								shaderAssetData.Reset();
								this.datas.Add(shaderAssetData);
								bool flag5 = this.datas.Count % 100 == 0;
								if (flag5)
								{
									ToolsHelper.GC();
								}
							}
						}
					}
				}
			}
			Singleton<PerformanceMeasurer>.Instance.StopStateExecutionMeasure((long)this.datas.Count);
		}

		// Token: 0x17000386 RID: 902
		// (get) Token: 0x0600112D RID: 4397 RVA: 0x00050D6C File Offset: 0x0004EF6C
		public override string TableTag
		{
			get
			{
				return "proj_shader";
			}
		}
	}
}
